<template >
  <div class="ordermanage-container">
    <breadcrumb style="position: absolute;width:100%;"></breadcrumb>
    <div class="content">
      <div class="query">
        <div class="margin_right_20">
          订单编号:&nbsp;
          <el-input
            v-model="orderNo"
            placeholder="请输入订单编号"
            style="width:200px;height:30px;"
            @keyup.enter.native="get_orderList(1)"
          ></el-input>
        </div>
        <div class="margin_right_20">
          用户ID:&nbsp;
          <el-input
            v-model="userNo"
            placeholder="请输入用户ID"
            style="width:100px;height:30px;"
            @keyup.enter.native="get_orderList(1)"
          ></el-input>
        </div>
        <div class="margin_right_20">
          商品名称:&nbsp;
          <el-input
            v-model="goodsName"
            placeholder="请输入商品名称"
            style="width:180px;height:30px;"
            @keyup.enter.native="get_orderList(1)"
          ></el-input>
        </div>
        <div class="margin_right_20">
          订单所属活动:&nbsp;
          <el-select v-model="positionId" style="width: 130px;">
            <el-option
              v-for="item in options1"
              :key="item.id"
              :label="item.position"
              :value="item.id"
            ></el-option>
          </el-select>
        </div>
        <!-- <div class="margin_right_20">
          售后类型:&nbsp;
          <el-select v-model="saleType" style="width: 110px;">
            <el-option
              v-for="item in options2"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </div>-->
        <div class="margin_right_20">
          发起者:&nbsp;
          <el-select v-model="sourceType" style="width: 110px;">
            <el-option
              v-for="item in options3"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </div>
        <div class="margin_right_20">
          操作作态:&nbsp;
          <el-select v-model="postSaleStatus" style="width: 110px;">
            <el-option
              v-for="item in options4"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </div>
        <div class="btn">
          <el-button type="primary" icon="el-icon-search" @click="get_orderList(1)">查询</el-button>
        </div>
      </div>

      <div class="query">
        <div class="start_time margin_right_20">
          创建时间(开始):&nbsp;
          <div class="block">
            <el-date-picker
              type="datetime"
              v-model="startTime"
              placeholder="选择日期时间"
              style="width:200px"
              value-format="yyyy-MM-dd HH:mm:ss"
            ></el-date-picker>
          </div>
        </div>
        <div class="end_time margin_right_20">
          创建时间(结束):&nbsp;
          <div class="block">
            <el-date-picker
              type="datetime"
              placeholder="选择日期时间"
              style="width:200px"
              v-model="endTime"
              default-time="23:59:59"
              value-format="yyyy-MM-dd HH:mm:ss"
            ></el-date-picker>
          </div>
        </div>
      </div>
      <div class="table">
        <el-table :data="orderList" style="width: 100%" height="548">
          <el-table-column prop="sourceType" label="发起者"></el-table-column>
          <el-table-column prop="orderNo" label="订单编号" width="200px"></el-table-column>
          <el-table-column prop="userNo" label="订单用户ID"></el-table-column>
          <el-table-column prop="goodPosition" label="订单所属活动"></el-table-column>
          <el-table-column prop="goodsName" label="商品名称" width="400px"></el-table-column>
          <el-table-column prop="amount" label="订单金额"></el-table-column>
          <!-- <el-table-column prop="saleType" label="售后类型"></el-table-column> -->
          <el-table-column prop="createtime" label="创建时间" width="200"></el-table-column>
          <el-table-column prop="postSaleStatus" label="操作状态" width="200"></el-table-column>
          <el-table-column label="操作" width="130">
            <template slot-scope="scope">
              <el-button
                type="text"
                size="small"
                v-if="scope.row.postSaleStatus=='待审核'"
                @click="jump_order_modify(scope.row.id,scope.row.postSaleId)"
              >审核</el-button>
              <el-button
                type="text"
                size="small"
                v-if="scope.row.postSaleStatus=='退货件待收货'"
                @click="jump_order_fetch(scope.row.id,scope.row.postSaleId)"
              >收货</el-button>
              <el-button
                type="text"
                size="small"
                v-if="scope.row.postSaleStatus=='退货件已收货'"
                @click="jump_order_send(scope.row.id,scope.row.postSaleId)"
              >退款</el-button>
              <el-button type="text" size="small" @click="jump_order_detail(scope.row.id)">详情</el-button>
            </template>
          </el-table-column>
        </el-table>
        <pagination
          :currentPage="currentPage"
          :page="page"
          :total="total"
          :pageSize="pageSize"
          @change-current="currentChange"
          @change-size="sizeChange"
        ></pagination>
      </div>
    </div>
  </div>
</template>
<script>
import breadcrumb from "../../components/breadcrumb";
import pagination from "../../components/page";
import { mapActions } from "vuex";
export default {
  components: { breadcrumb, pagination },
  data() {
    return {
      currentPage: 1,
      pageSize: 10,
      page: 1,
      total: 0,
      options1: [],
      options2: [
        { value: "", label: "全部" },
        { value: "1", label: "退货" },
        { value: "2", label: "换货" },
        { value: "3", label: "退款" }
      ],
      options3: [
        { value: "", label: "全部" },
        { value: "0", label: "用户" },
        { value: "1", label: "系统" }
      ],
      options4: [
        { value: "", label: "全部" },
        { value: "1", label: "待审核" },
        { value: "2", label: "审核通过" },
        { value: "3", label: "审核驳回" },
        { value: "4", label: "换货待收货" },
        { value: "5", label: "换货已收货" },
        { value: "6", label: "换货件寄回" },
        { value: "7", label: "退货件待收货" },
        { value: "8", label: "退货件已收货" },
        { value: "9", label: "退款完成" },
        { value: "10", label: "撤销申请" }
      ],
      orderList: [],
      orderNo: "",
      userNo: "",
      goodsName: "",
      positionId: "",
      saleType: "",
      sourceType: "",
      postSaleStatus: "",
      startTime: "",
      endTime: ""
    };
  },
  created() {
    if (localStorage.getItem("pageMsg")) {
      let pageMsg = JSON.parse(localStorage.getItem("pageMsg"));
      this.currentPage = pageMsg.currentPage;
      this.pageSize = pageMsg.pageSize;
      this.orderNo = pageMsg.orderNo;
      this.userNo = pageMsg.userNo;
      this.goodsName = pageMsg.goodsName;
      this.positionId = pageMsg.positionId;
      this.sourceType = pageMsg.sourceType;
      this.postSaleStatus = pageMsg.postSaleStatus;
      this.startTime = pageMsg.startTime;
      this.endTime = pageMsg.endTime;
      localStorage.removeItem("pageMsg");
    }
    this.get_orderList();
    // 获取商品类型
    this.positions();
  },
  methods: {
    positions() {
      this.$axios.post("/web_goods_pos/list").then(res => {
        this.options1 = res.data.data;
        this.options1.unshift({ id: "", position: "全部" });
      });
    },
    sizeChange(val) {
      this.pageSize = val;
      this.currentPage = 1;
      this.get_orderList();
    },
    currentChange(val) {
      this.currentPage = val;
      this.get_orderList();
    },
    jump_order_detail(id) {
      localStorage.setItem("path", JSON.stringify(this.$route.path));
      localStorage.setItem(
        "pageMsg",
        JSON.stringify({
          currentPage: this.currentPage,
          pageSize: this.pageSize,
          orderNo: this.orderNo,
          userNo: this.userNo,
          goodsName: this.goodsName,
          positionId: this.positionId,
          sourceType: this.sourceType,
          postSaleStatus: this.postSaleStatus,
          startTime: this.startTime,
          endTime: this.endTime
        })
      );
      this.$router.push("/exchangeRefundDetails?id=" + id);
    },
    jump_order_modify(id, postSaleId) {
      localStorage.setItem("path", JSON.stringify(this.$route.path));
      localStorage.setItem(
        "pageMsg",
        JSON.stringify({
          currentPage: this.currentPage,
          pageSize: this.pageSize,
          orderNo: this.orderNo,
          userNo: this.userNo,
          goodsName: this.goodsName,
          positionId: this.positionId,
          sourceType: this.sourceType,
          postSaleStatus: this.postSaleStatus,
          startTime: this.startTime,
          endTime: this.endTime
        })
      );
      this.$router.push(
        "/exchangeRefundAudit?id=" + id + "&postSaleId=" + postSaleId
      );
    },
    get_orderList() {
      var data =
        "current=" +
        this.currentPage +
        "&size=" +
        this.pageSize +
        "&orderNo=" +
        this.orderNo +
        "&userNo=" +
        this.userNo +
        "&goodsName=" +
        this.goodsName +
        "&positionId=" +
        this.positionId +
        "&saleType=1" +
        "&sourceType=" +
        this.sourceType +
        "&postSaleStatus=" +
        this.postSaleStatus +
        "&startTime=" +
        this.startTime +
        "&endTime=" +
        this.endTime;
      this.$axios.post("/web_order/postSale_page", data).then(result => {
        if (result.data.status == 0) {
          this.orderList = result.data.data.records;
          this.total = result.data.data.total;
          this.page = result.data.data.pages;
          this.orderList.forEach(item => {
            item.sourceType = this.options3[item.sourceType + 1].label;
            this.status_ = this.options4[item.postSaleStatus].value;
            item.postSaleStatus = this.options4[item.postSaleStatus].label;
          });
        }
      });
    },
    //收货
    jump_order_fetch(id, postSaleId) {
      // let data = {
      //   postSaleId: postSaleId
      // };
      this.$axios
        .post("/web_order/postSale_takeDelivery?postSaleId=" + postSaleId)
        .then(result => {
          if (result.data.status == 0) {
            if (result.data.data == true) {
              this.get_orderList();
              return this.$message({
                type: "success",
                message: "操作成功"
              });
            } else {
              return this.$message({
                type: "warning",
                message: "操作失败"
              });
            }
          }
        });
    },
    //退款
    jump_order_send(id, postSaleId) {
      localStorage.setItem("path", JSON.stringify(this.$route.path));
      localStorage.setItem(
        "pageMsg",
        JSON.stringify({
          currentPage: this.currentPage,
          pageSize: this.pageSize,
          orderNo: this.orderNo,
          userNo: this.userNo,
          goodsName: this.goodsName,
          positionId: this.positionId,
          sourceType: this.sourceType,
          postSaleStatus: this.postSaleStatus,
          startTime: this.startTime,
          endTime: this.endTime
        })
      );
      this.$router.push(
        "/exchangeRefundModify?id=" + id + "&postSaleId=" + postSaleId
      );
    },

    // 校验结束时间
    verfy_startTime() {
      if (this.startTime) {
        this.timeCompare(1);
      }
    },
    //   校验结束时间
    verfy_endtime() {
      if (this.endTime) {
        this.timeCompare(2);
      }
    },

    timeCompare(flag) {
      //  flag  用于标记是清楚开始时间，还是清楚结束时间
      if (
        new Date(this.startTime).getTime() >= new Date(this.endTime).getTime()
      ) {
        if (flag == 1) {
          this.startTime = "";
        } else {
          this.endTime = "";
        }
        return this.$message({
          type: "warning",
          message: "'拼团创建时间-开始'必须小于'拼团创建时间-结束'"
        });
      }
    }
  }
};
</script>

<style lang="less" >
.ordermanage-container {
  @import "../../style/table.less";
  @import "../../style/content.less";
  display: flex;
  flex-flow: column;
  position: relative;
  height: 100%;
  .el-table .cell {
    white-space: pre-line !important;
  }

  //更改行高
  .el-table__row td {
    height: 50px;
    padding: 0;
  }
  .el-table .cell {
    white-space: pre-line !important;
  }
  .content {
    .query {
      .start_time {
        display: flex;
        align-items: center;
      }
      .end_time {
        display: flex;
        align-items: center;
      }
      .btn {
        .el-button {
          width: 70px;
        }
      }
    }
  }
}
</style>

